package cn.itcast.java.stream;

import java.io.*;

/**
 * Author itcast
 * Date 2021/10/13 5:38
 * Desc TODO
 */
public class BufferedInputStreamDemo {
    public static void main(String[] args) throws IOException {
        //1.通过字节缓冲输出流往文件中写一句话.
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("data/output/abc.txt"));
        byte[] bytes = "hello the world".getBytes();
        bos.write(bytes,0,bytes.length);
        bos.write('\n');
        bos.flush();
        //2.通过字节缓冲输入流读取文件中的内容.
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("data/output/abc.txt"));
        byte[] bts = new byte[5];
        int len = 0;
        while ((len = bis.read(bts)) != -1) {
            System.out.print(new String(bts, 0, len));
        }
    }
}
